﻿<UserControl x:Class="Samba.Modules.UserModule.UserRoleView" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
     xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
     xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:Common="clr-namespace:Samba.Presentation.Common;assembly=Samba.Presentation.Common"
     mc:Ignorable="d" d:DesignHeight="300" d:DesignWidth="300">
    <UserControl.Resources>
        <CollectionViewSource x:Key="viewSource" Source="{Binding Permissions}">
            <CollectionViewSource.GroupDescriptions>
                <PropertyGroupDescription PropertyName="Category" />
            </CollectionViewSource.GroupDescriptions>
        </CollectionViewSource>
    </UserControl.Resources>
    <ScrollViewer Common:KineticBehaviour.HandleKineticScrolling="True" VerticalScrollBarVisibility="Auto">
        <Grid>
            <StackPanel>
                <Label Content="{LocText UserRoleName, Suffix=':'}" />
                <TextBox HorizontalAlignment="Left" MinWidth="200" Text="{Binding Name, Mode=TwoWay}" />
                <Label Content="{LocText Department, Suffix=':'}" />
                <ComboBox ItemsSource="{Binding Departments}" SelectedValue="{Binding DepartmentId}"
                     SelectedValuePath="Id" DisplayMemberPath="Name" Width="150" HorizontalAlignment="Left" />
                <Label>
                    <LocText ResourceIdentifierKey="Permissions" Suffix=":"/>
                </Label>
                <CheckBox IsChecked="{Binding IsAdmin, Mode=TwoWay}">
                    <LocText ResourceIdentifierKey="Admin"/>
                </CheckBox>
                <Border BorderThickness="1" BorderBrush="Silver" MinWidth="250" HorizontalAlignment="Left">
                    <ItemsControl ItemsSource="{Binding Source={StaticResource viewSource}}">
                        <ItemsControl.GroupStyle>
                            <GroupStyle>
                                <GroupStyle.ContainerStyle>
                                    <Style TargetType="{x:Type GroupItem}">
                                        <Setter Property="Margin" Value="0,0,0,5" />
                                        <Setter Property="Template">
                                            <Setter.Value>
                                                <ControlTemplate TargetType="{x:Type GroupItem}">
                                                    <Expander IsExpanded="False" BorderBrush="#FFA4B97F" BorderThickness="0,0,0,1">
                                                        <Expander.Header>
                                                            <DockPanel>
                                                                <TextBlock FontWeight="Bold" Text="{Binding Path=Name}" Margin="5,0,0,0" Width="150" />
                                                            </DockPanel>
                                                        </Expander.Header>
                                                        <Expander.Content>
                                                            <ItemsPresenter />
                                                        </Expander.Content>
                                                    </Expander>
                                                </ControlTemplate>
                                            </Setter.Value>
                                        </Setter>
                                    </Style>
                                </GroupStyle.ContainerStyle>
                            </GroupStyle>
                        </ItemsControl.GroupStyle>
                        <ItemsControl.ItemTemplate>
                            <DataTemplate>
                                <!--<Grid>
                                <Grid.ColumnDefinitions>
                                    <ColumnDefinition Width="*"/>
                                    <ColumnDefinition Width="auto"/>
                                </Grid.ColumnDefinitions>
                                <TextBlock VerticalAlignment="Center" Text="{Binding Title}" Grid.Column="0"></TextBlock>
                                <ComboBox MinWidth="60" Grid.Column="1" SelectedItem="{Binding Value}" ItemsSource="{Binding Values}"/>
                            </Grid>-->
                                <CheckBox Margin="5,0,0,0" Content="{Binding Title}" IsChecked="{Binding IsPermitted}" />
                            </DataTemplate>
                        </ItemsControl.ItemTemplate>
                    </ItemsControl>
                </Border>
                <Button HorizontalAlignment="Left" Margin="0,10" MinWidth="70" Content="{Binding SaveCommand.Caption}"
                     Command="{Binding SaveCommand}" />
                <Label Content="{Binding Error}" Foreground="Red" />
            </StackPanel>
        </Grid>
    </ScrollViewer>
</UserControl>